/*
 * frmSchedule.java
 *
 * Created on May 2, 2010, 2:09 AM
 */
package GUI;

import Entity.Schedule;
import Validate_Connect.DataInteraction;
import Validate_Connect.GUIInteraction;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author  Shinichi
 */
public class frmSchedule extends javax.swing.JInternalFrame {

    /** Creates new form frmSchedule */
    public frmSchedule() {
        initComponents();
        GUIInteraction.readToCombo("select *from tblClass", _cboClassName, "ClassName");
        GUIInteraction.readToCombo("select *from tblCourses", _cboCoursesName, "CoursesName");
        GUIInteraction.readToCombo("select *from tblUser where RoleID <> 'ADM'", _cboFullName, "FullName");
        refreshForm();
        _txtStartDate.setEditable(false);
        _txtEndDate.setEditable(false);
        _btnreset.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        _btndelete = new javax.swing.JButton();
        _btnaddNew = new javax.swing.JButton();
        _btnreset = new javax.swing.JButton();
        _btnupdate = new javax.swing.JButton();
        _btnprint = new javax.swing.JButton();
        _btnclose = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        _txtCheduleID = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        _cboClassName = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        _cboCoursesName = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        _cboFullName = new javax.swing.JComboBox();
        _txtStartDate = new javax.swing.JTextField();
        _txtEndDate = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        _tblSchedule = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false;   //Disallow the editing of any cell
            }
        };
        _tblSchedule.getTableHeader().setReorderingAllowed(false);
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("AITSM - Schedule");

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        _btndelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        _btndelete.setText("Delete");
        _btndelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btndeleteActionPerformed(evt);
            }
        });

        _btnaddNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/list_add2.png"))); // NOI18N
        _btnaddNew.setText("Add New");
        _btnaddNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnaddNewActionPerformed(evt);
            }
        });

        _btnreset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/reset2.png"))); // NOI18N
        _btnreset.setText("Reset");
        _btnreset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnresetActionPerformed(evt);
            }
        });

        _btnupdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/update2.png"))); // NOI18N
        _btnupdate.setText("Update");
        _btnupdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnupdateActionPerformed(evt);
            }
        });

        _btnprint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/printer2.png"))); // NOI18N
        _btnprint.setText("Print");
        _btnprint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnprintActionPerformed(evt);
            }
        });

        _btnclose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Logout16x16.png"))); // NOI18N
        _btnclose.setText("Close");
        _btnclose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btncloseActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Information"));

        jLabel2.setText("Schedule ID:");

        _txtCheduleID.setEditable(false);

        jLabel3.setText("ClassName:");

        jLabel4.setText("CoursesName:");

        jLabel5.setText("User FullName:");

        jLabel6.setText("Start Date:");

        jLabel7.setText("End Date:");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                        .add(jLabel2)
                        .add(30, 30, 30)
                        .add(_txtCheduleID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel3)
                        .add(21, 21, 21)
                        .add(_cboClassName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(239, 239, 239))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel4)
                            .add(jLabel5)
                            .add(jLabel6)
                            .add(jLabel7))
                        .add(19, 19, 19)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(_cboFullName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 218, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(_cboCoursesName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 91, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, _txtEndDate)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, _txtStartDate, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(_txtCheduleID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3)
                    .add(_cboClassName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(_cboCoursesName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(_cboFullName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(_txtStartDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(_txtEndDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Schedule List"));

        _tblSchedule.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        _tblSchedule.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                _tblScheduleMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(_tblSchedule);

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
        );

        jPanel1.setBackground(new java.awt.Color(0, 102, 102));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Schedule");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(339, 339, 339)
                .add(jLabel1)
                .addContainerGap(395, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jLabel1)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(_btndelete, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(_btnaddNew))
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel4Layout.createSequentialGroup()
                                .add(30, 30, 30)
                                .add(_btnreset, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                                .add(30, 30, 30)
                                .add(_btnupdate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(31, 31, 31)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(_btnprint, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(_btnclose, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jPanel2, 0, 362, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(_btnaddNew)
                            .add(_btnreset)
                            .add(_btnprint))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(_btnupdate)
                            .add(_btndelete)
                            .add(_btnclose)))
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void _btndeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btndeleteActionPerformed
    int i = Integer.valueOf(_txtCheduleID.getText());
    Interact.Schedules.deleteSchedule(i);
    refreshForm();
    resetForm();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btndeleteActionPerformed

private void _btnaddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnaddNewActionPerformed
    if (_btnaddNew.getText().equals("Add New")) {
        resetForm();
        _txtStartDate.setEditable(true);
        _txtEndDate.setEditable(true);
        _btnaddNew.setText("Save");
        _txtStartDate.requestFocus();
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(false);
    } else {
        Entity.Schedule _sch = new Schedule();
        String _codeClassID = DataInteraction.getCodeString("tblClass", "ClassName", _cboClassName.getSelectedItem().toString(), "ClassID");
        String _codeCoursesID = DataInteraction.getCodeString("tblCourses", "CoursesName", _cboCoursesName.getSelectedItem().toString(), "CoursesID");
        String _codeUserID = DataInteraction.getCodeString("tblUser", "FullName", _cboFullName.getSelectedItem().toString(), "UserID");
        _sch.set_ClassID(_codeClassID);
        _sch.set_CoursesID(_codeCoursesID);
        _sch.set_UserID(_codeUserID);
        _sch.set_StartDate(_txtStartDate.getText());
        _sch.set_EndDate(_txtEndDate.getText());
        Interact.Schedules.insertSchedule(_sch);
        JOptionPane.showMessageDialog(null, "Insert succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        refreshForm();
        resetForm();
        _txtStartDate.setEditable(false);
        _txtEndDate.setEditable(false);
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(true);
        _btnaddNew.setText("Add New");
    }


}//GEN-LAST:event__btnaddNewActionPerformed

private void _btnresetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnresetActionPerformed
    resetForm();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btnresetActionPerformed

private void _btnupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnupdateActionPerformed
    if (_btnupdate.getText().equals("Update")) {
        _txtStartDate.setEditable(true);
        _txtEndDate.setEditable(true);
        _btnaddNew.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setText("Save");
        _txtStartDate.requestFocus();
    } else {
        Entity.Schedule _sch = new Schedule();
        String _codeClassID = DataInteraction.getCodeString("tblClass", "ClassName", _cboClassName.getSelectedItem().toString(), "ClassID");
        String _codeCoursesID = DataInteraction.getCodeString("tblCourses", "CoursesName", _cboCoursesName.getSelectedItem().toString(), "CoursesID");
        String _codeUserID = DataInteraction.getCodeString("tblUser", "FullName", _cboFullName.getSelectedItem().toString(), "UserID");
        _sch.set_ScheduleID(Integer.valueOf(_txtCheduleID.getText()));
        _sch.set_ClassID(_codeClassID);
        _sch.set_CoursesID(_codeCoursesID);
        _sch.set_UserID(_codeUserID);
        _sch.set_StartDate(_txtStartDate.getText());
        _sch.set_EndDate(_txtEndDate.getText());

        Interact.Schedules.updateSchedule(_sch);
        JOptionPane.showMessageDialog(null, "Update succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        refreshForm();
        resetForm();
        _txtStartDate.setEditable(false);
        _txtEndDate.setEditable(false);
        _btnaddNew.setEnabled(true);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnupdate.setText("Update");
    }


}//GEN-LAST:event__btnupdateActionPerformed

private void _btnprintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnprintActionPerformed
    ConnectDB.ConnectDB.runReport("src\\Report\\reportScheduleList.jasper");
}//GEN-LAST:event__btnprintActionPerformed

private void _btncloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btncloseActionPerformed
    int i = JOptionPane.showConfirmDialog(null, "Dou you want to exit?", "Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (i == 0) {
        this.dispose();
    }
}//GEN-LAST:event__btncloseActionPerformed

private void _tblScheduleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event__tblScheduleMouseClicked
    int i = _tblSchedule.getSelectedRow();
    _txtCheduleID.setText(String.valueOf(_tblSchedule.getValueAt(i, 0)));
    _cboClassName.setSelectedItem(_tblSchedule.getValueAt(i, 2));
    _cboCoursesName.setSelectedItem(_tblSchedule.getValueAt(i, 3));
    _cboFullName.setSelectedItem(_tblSchedule.getValueAt(i, 1));
    _txtStartDate.setText(String.valueOf(_tblSchedule.getValueAt(i, 4)));
    _txtEndDate.setText(String.valueOf(_tblSchedule.getValueAt(i, 5)));
    _btnreset.setEnabled(true);
    _btndelete.setEnabled(true);
    _btnupdate.setEnabled(true);
    _btnprint.setEnabled(true);
    _btnclose.setEnabled(true);
    _btnaddNew.setEnabled(true);
    _txtStartDate.setEditable(false);
    _txtEndDate.setEditable(false);
    if (_btnaddNew.getText().equals("Save")) {
        _btnaddNew.setText("Add New");
    }
    if(_btnupdate.getText().equals("Save")){
        _btnupdate.setText("Update");
    }
}//GEN-LAST:event__tblScheduleMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _btnaddNew;
    private javax.swing.JButton _btnclose;
    private javax.swing.JButton _btndelete;
    private javax.swing.JButton _btnprint;
    private javax.swing.JButton _btnreset;
    private javax.swing.JButton _btnupdate;
    private javax.swing.JComboBox _cboClassName;
    private javax.swing.JComboBox _cboCoursesName;
    private javax.swing.JComboBox _cboFullName;
    private javax.swing.JTable _tblSchedule;
    private javax.swing.JTextField _txtCheduleID;
    private javax.swing.JTextField _txtEndDate;
    private javax.swing.JTextField _txtStartDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    public void refreshForm() {
        try {
            GUIInteraction.readToTable("select s.ScheduleID, u.FullName, c.ClassName, co.CoursesName, convert(char(10),s.StartDate,101) as StartDate, convert(char(10),s.EndDate,101) as EndDate from tblSchedule s right join tblClass c on s.ClassID=c.ClassID right join tblCourses co on co.CoursesID = s.CoursesID inner join tblUser u on s.UserID = u.UserID", _tblSchedule);
        } catch (SQLException ex) {
            Logger.getLogger(frmSchedule.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void resetForm() {
        _txtCheduleID.setText("");
        _cboClassName.setSelectedIndex(0);
        _cboCoursesName.setSelectedIndex(0);
        _cboFullName.setSelectedIndex(0);
        _txtStartDate.setText("");
        _txtEndDate.setText("");
    }
}
